<?php

require_once dirname(__FILE__).'/../lib/inicioGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/inicioGeneratorHelper.class.php';

/**
 * inicio actions.
 *
 * @package    odontopc
 * @subpackage inicio
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class inicioActions extends autoInicioActions
{
 
  public function executeIndex(sfWebRequest $request)
  {
    if ($request->getParameter('page')){
      $this->setPage($request->getParameter('page'));
    }	
	parent::executeIndex($request);
	$q = Doctrine::getTable('Pedido')->createQuery('p')->where('p.vendido = 0')->orderBy('p.fecha DESC')->limit('10');
	if($this->getUser()->hasPermission('cliente')){
		$id_usuario = $this->getUser()->getGuardUser()->getId();
		$clientes = Doctrine::getTable('Cliente')->findByUsuarioId($id_usuario);
		$id_cliente = $clientes[0]->getId();	
		$q->andWhere('p.cliente_id = ?', $id_cliente);
	}else{
	    $this->pager = $this->getPager();
		$this->sort = $this->getSort();
	}
	$this->pager2 = $q->execute();
  }  
  
}
